package com.example.demo.generator.codegen.model;

import java.util.Objects;

/**
 * Column level details derived from SpringBootCodeGenerator parsing logic.
 */
public class FieldInfo {

    /**
     * 原始列名。
     */
    private String columnName;
    /**
     * 生成后的字段名。
     */
    private String fieldName;
    /**
     * 推导出的 Java 类型。
     */
    private String fieldClass;
    /**
     * Swagger 中展示的类型。
     */
    private String swaggerClass;
    /**
     * 字段备注。
     */
    private String fieldComment;
    /**
     * 是否为主键列。
     */
    private boolean primaryKey;
    /**
     * 是否存在单列唯一约束。
     */
    private boolean unique;
    /**
     * 是否允许为 null。
     */
    private boolean nullable = true;
    /**
     * 是否为自增列。
     */
    private boolean autoIncrement;
    /**
     * 默认值定义。
     */
    private String defaultValue;

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getFieldClass() {
        return fieldClass;
    }

    public void setFieldClass(String fieldClass) {
        this.fieldClass = fieldClass;
    }

    public String getSwaggerClass() {
        return swaggerClass;
    }

    public void setSwaggerClass(String swaggerClass) {
        this.swaggerClass = swaggerClass;
    }

    public String getFieldComment() {
        return fieldComment;
    }

    public void setFieldComment(String fieldComment) {
        this.fieldComment = fieldComment;
    }

    public boolean isPrimaryKey() {
        return primaryKey;
    }

    public void setPrimaryKey(boolean primaryKey) {
        this.primaryKey = primaryKey;
    }

    public boolean isUnique() {
        return unique;
    }

    public void setUnique(boolean unique) {
        this.unique = unique;
    }

    public boolean isNullable() {
        return nullable;
    }

    public void setNullable(boolean nullable) {
        this.nullable = nullable;
    }

    public boolean isAutoIncrement() {
        return autoIncrement;
    }

    public void setAutoIncrement(boolean autoIncrement) {
        this.autoIncrement = autoIncrement;
    }

    public String getDefaultValue() {
        return defaultValue;
    }

    public void setDefaultValue(String defaultValue) {
        this.defaultValue = defaultValue;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof FieldInfo)) {
            return false;
        }
        FieldInfo fieldInfo = (FieldInfo) o;
        return primaryKey == fieldInfo.primaryKey
                && unique == fieldInfo.unique
                && nullable == fieldInfo.nullable
                && autoIncrement == fieldInfo.autoIncrement
                && Objects.equals(columnName, fieldInfo.columnName)
                && Objects.equals(fieldName, fieldInfo.fieldName)
                && Objects.equals(fieldClass, fieldInfo.fieldClass)
                && Objects.equals(swaggerClass, fieldInfo.swaggerClass)
                && Objects.equals(fieldComment, fieldInfo.fieldComment)
                && Objects.equals(defaultValue, fieldInfo.defaultValue);
    }

    @Override
    public int hashCode() {
        return Objects.hash(columnName, fieldName, fieldClass, swaggerClass, fieldComment, primaryKey, unique, nullable, autoIncrement, defaultValue);
    }

    @Override
    public String toString() {
        return "FieldInfo{" +
                "columnName='" + columnName + '\'' +
                ", fieldName='" + fieldName + '\'' +
                ", fieldClass='" + fieldClass + '\'' +
                ", swaggerClass='" + swaggerClass + '\'' +
                ", fieldComment='" + fieldComment + '\'' +
                ", primaryKey=" + primaryKey +
                ", unique=" + unique +
                ", nullable=" + nullable +
                ", autoIncrement=" + autoIncrement +
                ", defaultValue='" + defaultValue + '\'' +
                '}';
    }
}
